import type { UploadUserFile } from "element-plus";

export interface GetSpuListParams {
  page: number;
  limit: number;
  category3Id: number;
}
/*
spu列表的响应结果
{
  "records": [
    {
      "id": 3728,
      "spuName": "qeq",
      "description": "bbb",
      "category3Id": 1,
      "tmId": 26,
      "spuSaleAttrList": null,
      "spuImageList": null
    }
  ],
  "total": 11,
  "size": 1,
  "current": 1,
  "searchCount": true,
  "pages": 11
},
*/
export interface SpuItem {
  id?: number;
  spuName: string;
  description: string;
  category3Id?: number;
  tmId?: number;
}
export interface SpuSaleAttrValueItem {
  baseSaleAttrId: number;
  saleAttrValueName: string;
  id?: number;
  isChecked?: string;
  saleAttrName?: string;
  spuId?: number;
}
export type SpuSaleAttrValueList = SpuSaleAttrValueItem[];

export interface SpuImageItem {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number;
  isDefault?: "1" | "0";
}
export type SpuImageList = SpuImageItem[];
export interface SpuSaleAttrItem {
  baseSaleAttrId: number;
  isShowEdit?: boolean;
  id?: number;
  saleAttrName: string;
  spuId?: number;
  spuSaleAttrValueList: SpuSaleAttrValueList;
}
export type SpuSaleAttrList = SpuSaleAttrItem[];
// 添加Spu组件，需要的spuFormData数据类型
export interface SpuFormData extends SpuItem {
  spuSaleAttrList: SpuSaleAttrList;
  spuImageList: UploadUserFile[];
}
// 添加/修改Spu接口参数类型(添加不要id，修改要id)
export interface AddOrUpdateSpuParams extends SpuItem {
  spuImageList: SpuImageList;
  spuSaleAttrList: SpuSaleAttrList;
}
// SpuList展示数据类型spuList
export type SpuList = SpuItem[];

export interface GetSpuListResponse {
  records: SpuList;
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
}
/*
销售属性列表的响应结果
 [
    {
      "id": 1,
      "name": "颜色"
    },
    {
      "id": 2,
      "name": "版本"
    },
    {
      "id": 3,
      "name": "尺码"
    }
  ]
*/
export interface GetBaseSaleAttrItem {
  id: number;
  name: string;
}
export type GetBaseSaleAttrList = GetBaseSaleAttrItem[];
/*
1. 分析每个情况需要什么类型
2. 共有类型定义成必选属性，独有类型定义成可选属性

 SpuList展示数据类型spuList = SpuItem[]
  SpuItem
    {
      id: number;
      spuName: string;
      description: string;
    }
 添加Spu组件，需要的spuFormData数据类型(看表单)
  {
      spuName: string;
      tmId: number;
      description: string;
      // 组件spuImageList是给el-upload的v-model双向数据绑定的
      // 所以数据类型要符合el-upload组件类型定义（不符合会报类型错误）。看文档
      spuImageList: UploadUserFile[];
      spuSaleAttrList: [
        {
          baseSaleAttrId: number;
          saleAttrName: string;
          isShowEdit: boolean;
          spuSaleAttrValueList: [
            {
              baseSaleAttrId: number;
              saleAttrValueName: string;
            }
          ]
        }
      ];
    }
 添加Spu接口参数类型(不要id)
  {
      "category3Id": number,
      "description": "string",
      "spuImageList": [
        {
          "imgName": "string",
          "imgUrl": "string",
        }
      ],
      "spuName": "string",
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "saleAttrName": "string",
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
            }
          ]
        }
      ],
      "tmId": number
    }
 修改Spu接口参数类型(都要)
  {
      "category3Id": 0,
      "description": "string",
      "id": 0,
      "spuImageList": [
        {
          "id": 0,
          "imgName": "string",
          "imgUrl": "string",
          "spuId": 0
        }
      ],
      "spuName": "string",
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "id": 0,
          "saleAttrName": "string",
          "spuId": 0,
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
              "id": 0,
              "isChecked": "string",
              "saleAttrName": "string",
              "spuId": 0
            }
          ]
        }
      ],
      "tmId": 0
    }

*/
